<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>险种配置关系表 管理</title>
    <style type="text/css">
    </style>
    <jsp:include page="../../import.jsp" flush="true"/>
</head>

<body class="iframeBody">
<div class="Wrapper">
    <div class="searchArea">
        <form id="searchBar">
            <div class="fieldset1 clearFix">
                <div class="fieldBox">
                    <div class="label">险种名称</div>
                    <div class="field">
                        <input name="insTypId" id="insTypId" data-value="" placeholder="请选择" ltype="combobox">
                    </div>
                    <div class="label">事业部</div>
                    <div class="field">
                        <input name="buOrgCd" id="buOrgCd" data-value="" placeholder="请选择" ltype="combobox">
                    </div>
                    <div class="label">项目类型</div>
                    <div class="field">
                        <input name="prjTypCd" id="prjTypCd" data-value="" placeholder="请选择" ltype="combobox">
                    </div>

                    <div class="clearFix"></div>
                    <div class="btnsBox">
                        <span id="searchBtn" class="sq-button sq-button-round">查询</span>
                        <span id="clearBtn" class="sq-button sq-button-round">清空</span>
                        <span id="addBtn" class="sq-button sq-button-round">新增</span>
                        <span id="changeBtn" class="sq-button sq-button-round">修改</span>
                        <span id="delBtn" class="sq-button sq-button-round">删除</span>
                        <input id="resetBtn" type="reset" value="重置" class="l-button l-button-reset Hide"/>
                    </div>
                </div>
            </div>
        </form>
    </div>
    <div id="ligergrid1" class="sq-grid"></div>
</div>

<script type="text/javascript">
    var grid = null, menu = null;
    $(function () {
        $("#insTypId").ligerComboBox({
            valueField: 'key',
            textField: 'value'
        });
        $("#buOrgCd").ligerComboBox({
            valueField: 'key',
            textField: 'value',
            onChangeValue: function (value) {
                buOrgCd=liger.get("buOrgCd").getValue();
                $.ajax({
                    type: 'get',
                    dataType: 'json',
                    url: '<%=path%>/insurance/insTypCfgR/getPrjTypList.do?buOrgCd='+buOrgCd,
                    success: function (msg) {
                        if (msg.success == 1) {
                            liger.get("prjTypCd").setData(JSON.parse(msg.data));
                        }
                    }
                });
            }
        });
        $("#prjTypCd").ligerComboBox({
            valueField: 'key',
            textField: 'value'
        });

        grid = $("#ligergrid1").ligerGrid({
            url: '<%=path%>/insurance/insTypCfgR/initList.do',
            method: 'get',
            columns: [
                {display: '险种名称', name: 'insTypNm', minWidth: 100, align: 'center', enabledSort: false},
		        {display: '事业部', name: 'buOrgCdNm', minWidth: 100, align: 'center', enabledSort: false},
		        {display: '项目类型', name: 'prjTypCdNm', minWidth: 100, align: 'center', enabledSort: false},
                {display: '首年是否必要', name: 'isFstReq', minWidth: 100, align: 'center', enabledSort: false,
                    render:function(rowdata){
                        if(rowdata.isFstReq==1){
                            return "是";
                        }else{
                            return "否";
                        }
                    }
                },
                {display: '续保是否必要', name: 'isRenewReq', minWidth: 100, align: 'center', enabledSort: false,
                    render:function(rowdata){
                        if(rowdata.isRenewReq==1){
                            return "是";
                        }else{
                            return "否";
                        }
                    }
                },
            ],
            pageSize: 10,
            root: 'rows',
            record: 'total',
            hideLoadButton: true,
            width: '100%',
            height: '100%',
            heightDiff: -2,
            checkbox: true,
            rownumbers: true,
            allowUnSelectRow: true,
            alternatingRow: false
        });
        grid.setHeight(100);

        $("#searchBar").ligerForm();

        liger.get("insTypId").setData(${insTypCdList});
        liger.get("buOrgCd").setData(${buOrgCdList});

        $("#pageloading").hide();

        /* 查询 */
        $("#searchBtn").click(function (event) {
            var form = liger.get("searchBar");
            var data = form.getData();
            for (name in data) {
                grid.setParm(name, data[name]);
            }
            grid.reload();
        });

        /* 清空 */
        $("#clearBtn").click(function (event) {
            $("#resetBtn").click();  //重置 input-text
            var form = liger.get("searchBar");
            form.setData({  //重置select等特殊表单
                "*Cd": " "
            });
        });
        
        var callback = function () {
            grid.reload();
        };

        /* 新增 */
        $("#addBtn").click(function (event) {
            $.ligerDialog.SQopen({
                width: 550,
                height: 300,
                title: '新增险种配置关系表',
                url:'<%=path%>/insurance/insTypCfgR/toAddPage.do'
            });
        });

        /* 修改 */
        $("#changeBtn").click(function (event) {
            var selectedRows = grid.getSelectedRows();
            if (selectedRows.length != 1) {
                $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_ONLY_A_ROW, SQ_type: "warning"});
                return;
            }
            var _id=selectedRows[0].id;
            $.ligerDialog.SQopen({
                width: 550,
                height: 300,
                title: '修改险种配置关系表',
                url:'<%=path%>/insurance/insTypCfgR/toModifyPage.do?id='+_id
            });
        });

        /* 删除 */
        $("#delBtn").click(function () {
            var selectedRows = grid.getSelectedRows();
            if (selectedRows.length == 0) {
                $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_MORE_ROW, SQ_type: "warning"});
                return;
            }
            var _ids = [];
            for (var index in selectedRows) {
                _ids.push(selectedRows[index].id);
            }

            $.ligerDialog.confirm(LogUtils.LOG_CMM_DELETE_CONFIRM, function (flag) {
                if (flag == false)return;
                var wait_dialog;
                $.ajax({
                    type: 'post',
                    dataType: 'json',
                    data: {ids: JSON.stringify(_ids)},
                    url: '<%=path%>/insurance/insTypCfgR/removeByIds.do',
                    beforeSend: function () {
                        wait_dialog = $.ligerDialog.SQalert({
                            content: LogUtils.LOG_CMM_DATA_LOADING,
                            SQ_type: "waitting"
                        });
                    },
                    success: function (msg) {
                        wait_dialog.close();
                        if (msg.success == 1) {
                            $.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});
                            grid.reload();
                        } else {
                            $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                        }
                    }
                });
            });
        });

    });

</script>

</body>
</html>
